package main

import (
	"fmt"
	"log"
	"os"
	"os/exec"
	"strconv"
	"sync"
)

var wg sync.WaitGroup

//执行函数 execfun
func execfun(input int, pname string, agr ...string) {
	defer wg.Done()
	defer fmt.Printf("job:%d completed!\n", input)
	cmd := exec.Command(pname, agr...)
	buf, err := cmd.Output()
	if err != nil {
		log.Fatal(err)
		return
	}
	fmt.Printf("%s\n", buf)
}

func main() {
	defer fmt.Println("All job completad!")
	fmt.Println("now:开始执行...")
	count, _ := strconv.Atoi(os.Args[1])
	for i := 0; i < count; i++ {
		wg.Add(1)
		go execfun(i, os.Args[2], os.Args[3:]...)
	}
	wg.Wait()
}